<?php
$page_title = 'eTAT: Home';
require_once 'controller.php';

if(isset($_POST['add_course_submit'])) {
	$data = (object) array('title'=>$_POST['title'],'term'=>"{$_POST['term']} {$_POST['year']}",'description'=>$_POST['description']);
	$id = $instructor->addCourse($data);
	redirect("course.php?c=$id");
}

require_once 'header.php';
?>
<h1>Home</h1> <h2><a href="Graph_init.php">Graph</a></h2>
<h2><a href="Monitor.php">Monitor</a></h2>
<h2><a href="SanitizeDatabase.php">Sanitize Database</a></h2> <!-- Ravi -->
<h3>Courses:</h3>
<?php
$courses = $instructor->getAllCourses();
if($courses != null) {
	$count = 0;
	foreach($courses as $c) {
		$groups = $c->getAllGroups();
		print "<a href='course.php?c=$c->id'>$c->title</a><br>";
		$count++;
	}
} else {
?>
<p>Looks like you haven't added any courses for monitoring, yet.</p>
<p>Let's get started by pressing the <b>Add Course</b> button below:</p>
<?php
}
print newBtn('add_course','Add Course',array('type'=>'button','onclick'=>'popup("add-course",null)'));
$form = new Form('add_course_form','post');
$form->textInput('title','Course Title');
$form->textInput('term','Course Term',array(),false);
$form->textInput('year','',array('value'=>date('Y'),'size'=>'2'),false);
$form->textArea('description','Description (optional)',4,20);
$form->button('add_course_submit','Create',array('type'=>'submit'));
print popup('add-course',$form->build(),350,array('left'=>300,'top'=>(120+$count*15)));
?>

<div class='clear'></div>
<?php require_once 'footer.php'; ?>